package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.system.domain.ResCategory;
import com.ruoyi.system.mapper.ResCategoryMapper;
import com.ruoyi.system.service.IResCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ResInfoMapper;
import com.ruoyi.system.domain.ResInfo;
import com.ruoyi.system.service.IResInfoService;

/**
 * 餐馆Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-05-29
 */
@Service
public class ResInfoServiceImpl implements IResInfoService 
{
    @Autowired
    private ResInfoMapper resInfoMapper;

    @Autowired
    private ResCategoryMapper resCategoryMapper;

    @Autowired
    private IResCategoryService resCategoryService;

    /**
     * 查询餐馆
     * 
     * @param resId 餐馆主键
     * @return 餐馆
     */
    @Override
    public ResInfo selectResInfoByResId(Long resId)
    {
        ResInfo resInfo = resInfoMapper.selectResInfoByResId(resId);
        if (resInfo != null && resInfo.getCategoryId() != null) {
            ResCategory resCategory = resCategoryService.selectResCategoryByCategoryId(resInfo.getCategoryId());
            resInfo.setResCategory(resCategory);
        }
        return resInfo;
    }

    /**
     * 查询餐馆列表
     * 
     * @param resInfo 餐馆
     * @return 餐馆
     */
    @Override
    public List<ResInfo> selectResInfoList(ResInfo resInfo)
    {
        List<ResInfo> resInfoList = resInfoMapper.selectResInfoList(resInfo);
        for (ResInfo info : resInfoList) {
            Long categoryId = info.getCategoryId();
            ResCategory resCategory = resCategoryService.selectResCategoryByCategoryId(categoryId);
            info.setResCategory(resCategory);
        }
        return resInfoList;
    }

    @Override   // 根据分类查找餐馆列表
    public List<ResInfo> selectResInfoListByCategory(ResCategory category) {
        ResCategory resCategory = resCategoryMapper.selectResCategoryByCategoryId(category.getCategoryId());
        ResInfo resInfo = new ResInfo();
        resInfo.setCategoryId(resCategory.getCategoryId());
        List<ResInfo> resInfoList = resInfoMapper.selectResInfoList(resInfo);
        return resInfoList;
    }

    /**
     * 新增餐馆
     * 
     * @param resInfo 餐馆
     * @return 结果
     */
    @Override
    public int insertResInfo(ResInfo resInfo)
    {
        return resInfoMapper.insertResInfo(resInfo);
    }

    /**
     * 修改餐馆
     * 
     * @param resInfo 餐馆
     * @return 结果
     */
    @Override
    public int updateResInfo(ResInfo resInfo)
    {
        return resInfoMapper.updateResInfo(resInfo);
    }

    /**
     * 批量删除餐馆
     * 
     * @param resIds 需要删除的餐馆主键
     * @return 结果
     */
    @Override
    public int deleteResInfoByResIds(Long[] resIds)
    {
        return resInfoMapper.deleteResInfoByResIds(resIds);
    }

    /**
     * 删除餐馆信息
     * 
     * @param resId 餐馆主键
     * @return 结果
     */
    @Override
    public int deleteResInfoByResId(Long resId)
    {
        return resInfoMapper.deleteResInfoByResId(resId);
    }

    @Override
    public List<ResInfo> selectResInfoListByCategory(Integer resCategory, Integer type) {
        System.out.println("resCategory:" + resCategory+"type:"+type);
        return resInfoMapper.selectResInfoListByCategory(resCategory, type);
    }
}
